{% extends  'myadmin/index.html'%}

{% block title %}
<title>后台-商品列表</title>
{% endblock %}

{% block con %}
  <div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">商品列表</div>
                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <a href="{% url 'myadmin_goods_add' %}" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</a>
                                      
                                </div>
                            </div>
                        </div>
                    </div>
                <form>    
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select name='types' data-am-selected="{btnSize: 'sm'}" style="display: none;">
                              <option {% if request.GET.types == 'all' %} selected {% endif %} value="all">所有类型</option>
                              <option {% if request.GET.types == 'title' %} selected {% endif %} value="title">名称</option>
                              <option {% if request.GET.types == 'price' %} selected {% endif %} value="price">价钱</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input value="{{ request.GET.keywords }}" name='keywords' type="text" class="am-form-field ">
                            <span class="am-input-group-btn">
                                <button id="search" class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
                              </span>
                        </div>
                    </div>
                </form>  
                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>主图</th>
                                    <th>类型</th>
                                    <th>名称</th>
                                    <th>价格</th>
                                    <th>库存</th>
                                    <th>销量</th>
                                    <th>点击量</th>
                                    <th>状态</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for v in goodslist %}
                                <tr>
                                    <td>{{ v.id }}</td>
                                    <td>
                                        <img src="{{ v.pic_url }}" class="tpl-table-line-img" alt="" width="135" height="105">
                                    </td>
                                    <!-- 类型 -->
                                    <td class="am-text-middle">{{ v.cateid.name }}</td>
                                    <!-- 名称 -->
                                    <td class="am-text-middle">{{ v.title }}</td>
                                    <!-- 价钱 -->
                                    <td class="am-text-middle">{{ v.price }}</td>
                                    <!-- 库存 -->
                                    <td class="am-text-middle">{{ v.store }}</td>
                                    <!-- 销量 -->
                                    <td class="am-text-middle">{{ v.crdernum }}</td>
                                    <!-- 点击量 -->
                                    <td class="am-text-middle">{{ v.clicknum }}</td>
                                    <!-- 状态 -->
                                    <td class="am-text-middle">
                                        {% if v.status == '0' %}
                                            新品
                                        {% elif v.status == '1' %}    
                                            热卖
                                        {% elif v.status == '2' %}    
                                            下架
                                        {% else %}
                                            畅销
                                        {% endif %}
                                    </td>
                                    
                                    
                                    <td class="am-text-middle">{{ v.addtime }}</td>
                                    
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="{% url 'myadmin_goods_edit' v.id %}">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="{% url 'myadmin_goods_del' v.id %}" class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}

                                <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                                <!-- <li class="am-disabled"><a href="#">«</a></li> -->
                                {% load pagetag %}
                                
                                {% ShowPages goodslist.paginator.num_pages request %}
                                
                               <!-- <li><a href="#">»</a></li> -->
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    // 给搜索按钮绑定单机事件
    $('#search').click(function(){
        // 获取选框的值
        var v = $('select[name=types]').val()
        // 判断类型
        if(v == 'price'){
            // 获取输入的关键字,检测是否正确
            var k = $('input[name=keywords]').val()
            var reg = /^(\d+|\d+\.\d+),(\d+|\d+.\d+)$/
            if(!reg.test(k)){
                alert('格式有误,格式为xx,xx')
                return false;
              
            }
        }
    })
</script>

{% endblock %}